//
//  GRHoMeAction.m
//  YC_GRice
//
//  Created by Feng Liu on 2018/8/28.
//  Copyright © 2018年 YeCai. All rights reserved.
//

#import "GRHoMeAction.h"
#import "GRHotSearchModel.h"
#import "GRUltimateModel.h"
#import "GRVideoItem.h"
@implementation GRHoMeAction

+ (void)getLocationShops:(NSDictionary *)paramer completionHandler:(RequestBlock)completionHandler {
    NSString *url = [NSString stringWithFormat:@"%@onePay/index",GRDeliveryAPI];
    [RequestManager TouristsRequestWithURLString:url Method:GR_POST Paramers:paramer completionHandler:^(BOOL success, id responseObject, GRError *error) {
        if (success) {
            GRUltimateModel *homeModel = [GRUltimateModel yy_modelWithDictionary:responseObject];
            completionHandler(YES, homeModel, nil);
        }else {
            completionHandler(NO, nil, error);
        }
    }];
}


+ (void)getNearbyStore:(NSDictionary *)paramer completionHandler:(RequestBlock)completionHandler {
    NSString *url = [NSString stringWithFormat:@"%@onePay/nearbyStore",GRDeliveryAPI];
    [RequestManager TouristsRequestWithURLString:url Method:GR_POST Paramers:paramer completionHandler:^(BOOL success, id responseObject, GRError *error) {
        if (success) {
            NSArray *storeArr = responseObject[@"onePayInfos"];
            NSMutableArray *storeList = [NSMutableArray array];
            if (Array(storeArr)) {
                for (NSDictionary *dic in storeArr) {
                    GRUltimateShopModel *model = [GRUltimateShopModel yy_modelWithDictionary:dic];
                    [storeList addObject:model];
                }
            }
            completionHandler(YES, storeList, nil);
        }else {
            completionHandler(NO, nil, error);
        }
    }];
}

+ (void)TopSearch:(NSString *)areaCode completionHandler:(RequestBlock)completionHandler {
    NSString *url = [NSString stringWithFormat:@"%@onePay/areaCodeHot/%@",GRDeliveryAPI, areaCode];
    [RequestManager TouristsRequestWithURLString:url Method:GR_GET Paramers:nil completionHandler:^(BOOL success, id responseObject, GRError *error) {
        if (success) {
            NSMutableArray *searchList = [NSMutableArray array];
            if (Array(responseObject)) {
                for (NSDictionary *dic in responseObject) {
                    GRHotSearchModel *model = [GRHotSearchModel yy_modelWithDictionary:dic];
                    [searchList addObject:model];
                }
            }
            completionHandler(YES, searchList, nil);
        }else {
            completionHandler(NO, nil, error);
        }
    }];
}

+ (void)storeSearchResults:(NSDictionary *)paramer completionHandler:(RequestBlock)completionHandler {
    NSString *url = [NSString stringWithFormat:@"%@onePay/search",GRDeliveryAPI];
    [RequestManager TouristsRequestWithURLString:url Method:GR_POST Paramers:paramer completionHandler:^(BOOL success, id responseObject, GRError *error) {
        if (success) {
            NSArray *array                = responseObject[@"dataList"];
            NSMutableArray *storeList = [NSMutableArray array];
            if (Array(array)) {
                for (NSDictionary *dic in array) {
                    GRUltimateShopModel *model = [GRUltimateShopModel yy_modelWithDictionary:dic];
                    [storeList addObject:model];
                }
            }
            completionHandler(YES, storeList, nil);
        }else {
            completionHandler(NO, nil, error);
        }
    }];
}
+(void)getShortVideo:(NSDictionary *)paramer completionHandler:(RequestBlock)completionHandler{
    
    NSString * url =[NSString stringWithFormat:@"%@shortVideo/page",GRiceAPI ];
    [RequestManager TouristsRequestWithURLString:url Method:GR_GET Paramers:paramer completionHandler:^(BOOL success, id responseObject, GRError *error) {
          if (success) {
              NSArray *array                = responseObject[@"dataList"];
              NSMutableArray *videoList = [NSMutableArray array];
              if (Array(array)) {
                  for (NSDictionary * dic in array) {
                      GRVideoItem * videoItem = [GRVideoItem yy_modelWithDictionary:dic ];
                      [videoList addObject:videoItem];
                  }
              }
                completionHandler(YES, videoList, nil);
          }else{
                 completionHandler(NO, nil, error);
          }
        
    }];
    
}
+(void)getLotteryListcompletionHandler:(RequestBlock)completionHandler{
    NSString * url = [NSString stringWithFormat: @"%@v1/prize/lottery/0",GRiceAPI];
//    [RequestManager MembershipRequestWithURLString:<#(NSString *)#> Method:<#(GRMethod)#> Paramers:<#(NSDictionary *)#> completionHandler:<#^(BOOL success, id responseObject, GRError *error)completionHandler#>
    
    
}

@end
